<div class="row">
	<div class="col-lg-12">
		<h1 class="page-header">管理员编辑</h1>
	</div>
	<!-- /.col-lg-12 -->
</div>

<div class="row" id="orderFilterForm">
	<div class="col-lg-6">
		<div class="panel panel-danger">
			<div class="panel-heading"> 新增管理员 </div>
			<div class="panel-body">
				<div class="form-group">
					<label>管理员名字</label>
					<input id="adminName" placeholder="" class="form-control"/>
				</div>
				<div class="form-group">
					<label>权限</label>
					<select id="adminAuth" placeholder="" class="form-control">
					<?php foreach($auths as $_auth){?>
						<option value="<?php echo $_auth['id']?>"><?php echo $_auth['name']?></option>
					<?php }?>
					</select>
				</div>
				<div class="col-lg-2">
					<button onclick="addSubmit()" type="button" class="btn btn-primary btn-lg">新增</button>
				</div>
			</div>
		</div>
	</div>
</div>


<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading"> 现有管理员 </div>
			<div class="panel-body">
				<table width="100%" class="table table-striped table-bordered table-hover" id="adminManagerTable">
					<thead>
					<tr>
						<th>管理员名称</th>
						<th>管理员权限</th>
						<th>操作</th>
					</tr>
					</thead>
					<tbody>
					<?php foreach($admins as $_admin){
						?>
					<tr>
						<td><?php echo $_admin['name']?></td>
						<td><?php echo $auths[$_admin['auth_type']]['name']?></td>
						<td><button class="btn btn-danger btn-xs" type="button" onclick="deleteAdmin('<?php echo $_admin['id']?>')">删除</button>
						<button class="btn btn-warning btn-xs" type="button" onclick="modifyAdminAuth('<?php echo $_admin['id']?>', <?php echo $_admin['auth_type']?>)">修改权限</button>
						</td>
					</tr>
					<?php }?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
	<!-- /.col-lg-12 -->
</div>


<div class="modal fade" id="modifyAdminAuthModal" tabindex="-1" role="dialog" aria-labelledby="modifyAdminAuthModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">修改权限</h4>
			</div>
			<div class="modal-body">
				<div class="alert alert-danger" style="display:none">
					
				</div>
				<form>
					<div class="form-group">
						<label for="modifypwd_oldpassword" class="control-label">权限:</label>
						<select id="adminChangeAuth" placeholder="" class="form-control">
						<?php foreach($auths as $_auth){?>
							<option value="<?php echo $_auth['id']?>"><?php echo $_auth['name']?></option>
						<?php }?>
						</select>
						<input type="hidden" class="form-control" id="modifyAuthAdminId">
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				<button type="button" class="btn btn-primary" onclick="_modifyAdminAuth()">修改</button>
			</div>
		</div>
	</div>
</div>

<script>
$(document).ready(function(){
    $('#adminManagerTable').DataTable({
		//"pageLength": 50
	});
});

function addSubmit(){
	commonSend('adminAdd', {name: $("#adminName").val(), auth: $("#adminAuth").val()}, '新增成功', true);
}

function deleteAdmin(adminId){
	if(confirm('确定要删除管理员吗？')){
		commonSend('adminDelete', {adminId: adminId}, '删除成功', true);
	}
}

function modifyAdminAuth(adminId, auth){
	$("#modifyAuthAdminId").val(adminId);
	$("#adminChangeAuth").val(auth);
	$("#modifyAdminAuthModal").modal();
}

function _modifyAdminAuth(){
	$("#modifyAdminAuthModal").modal('hide');
	commonSend('adminModifyAuth', {adminId: $("#modifyAuthAdminId").val(), auth: $("#adminChangeAuth").val()}, '修改成功', true);
}
</script>